#include "comm.hpp"

int main()
{
    if (mkfifo(ipcPath.c_str(), MODE) < 0)
    { //创建管道文件
        perror("mkfifo");
        exit(0);
    }

    Log("pipe make success", Debug) << "step 1" << endl;
    //正常操作
    int fd = open(ipcPath.c_str(), O_RDONLY);
    if (fd < 0)
    {
        perror("open");
        exit(0);
    }
    //正常通信
    char buf[SIZE];
    while (true)
    {
        memset(buf, '\0', sizeof(buf));
        ssize_t s = read(fd, buf, sizeof(buf) - 1);
        if (s > 0)
        {
            cout << "client say" << buf << endl;
        }
        else if (s == 0)
        {
            // file end
            cerr << "read file end, client end, server end" << endl;
        }
        else
        {
            perror("read");
            exit(0);
        }
    }

    close(fd);
    return 0;
}